import java.util.*;

public class Solution {

    public int GetUglyNumber_Solution(int index) {

        if (index < 2) {
            return index;
        }

        Set<Long> set = new HashSet<>();
        PriorityQueue<Long> queue = new PriorityQueue<>();

        queue.add(1L);
        set.add(1L);

        long res = -1L;

        int[] arr = {2, 3, 5};

        for (int i = 0; i < index; i++) {
            res = queue.remove();
            
            for (int j = 0; j < 3; j++) {
                long temp1 = res * arr[j];
                
                if (!set.contains(temp1)) {
                    set.add(temp1);
                    queue.add(temp1);
                } 
            }

            System.out.println(res);
        }

        return (int)res;

    }
}